package com.yootoo.bsuser.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yootoo.bsuser.entity.User;
import com.yootoo.bsuser.mapper.UserMapper;
import com.yootoo.bsuser.service.IUserService;
import com.yootoo.common.enums.RedisKeyContont;
import com.yootoo.common.utils.MD5;

@Service(value = "userService")
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean addUser(User user) {
    	boolean updateFlag =false;
    	//密码加密
    	user.setPassword(MD5.MD5Encode(user.getPassword()));
    	user.setCreatedTime(new Date());
    	user.setCreator(user.getCreator());
    	
    	int insertCount =userMapper.insertSelective(user);
    	
    	if(insertCount == 1){
    		updateFlag =true;
    	}
    	
        return updateFlag;
    }
    //RedisKeyContonts.LOGIN_USER+
    @Override
    public User selectByNamePassWord(User user) {
    	//密码加密查询
    	user.setPassword(MD5.MD5Encode(user.getPassword()));
        return userMapper.selectByCondition(user);
    }


	@Override
	public User selectByName(User user) {
		return userMapper.selectByCondition(user);
	}


	@Override
	public  PageInfo<User> ListPage(int pageNum, int pageSize) {
		 PageHelper.startPage(pageNum, pageSize); 
		 List<User> videoList = userMapper.listBy();
		 PageInfo<User> pageInfo =new PageInfo<User>(videoList);
	     return  pageInfo ;
	}


	@Override
	public boolean updateByName(User user) {
		
		boolean updateFlag =false;
		
		int updateCount=userMapper.update(user);
		
		if(updateCount == 1){
			updateFlag =true;
		}
		
		return updateFlag;
	}
}